/**
 * 
 */
package com.app.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

import com.app.dao.BaseDao;
import com.app.dao.IUserDao;
import com.app.dao.po.CornUser;
import com.app.service.vo.UserVo;

/**
 * @author yuxk
 * 
 */
public class UserDaoImpl<T> extends BaseDao<T> implements IUserDao {

	private static Logger logger = Logger.getLogger(UserDaoImpl.class);

	public UserDaoImpl() {
		super();
		logger.info(this.getClass() + " loader");
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.app.dao.IUserDao#getAllUser()
	 */
	@Override
	public List<UserVo> getAllUser() {
		// TODO Auto-generated method stub
		logger.info(this.getClass() + "查询所有用户信息开始");
		List<CornUser> userpolist = this.getHibernateTemplate().loadAll(
				CornUser.class);
		List<UserVo> uservolist = new ArrayList<UserVo>();
		for (CornUser po : userpolist) {
			uservolist.add((UserVo) new UserVo().parseVo(po));
		}
		logger.info(this.getClass() + "查询所有用户信息完成");
		return uservolist;
	}

	@Override
	public void save(UserVo vo) {
		// TODO Auto-generated method stub
		logger.info(this.getClass() + "用户信息入库开始");
		CornUser po = new CornUser();
		this.getHibernateTemplate().save(vo.parsePo(new CornUser()));
		vo.setId(po.getId());
		logger.info(this.getClass() + "用户信息入库完成");
	}

	@Override
	public void updateUser(UserVo vo) {
		// TODO Auto-generated method stub
		logger.info(this.getClass() + "用户信息更新开始");
		this.getHibernateTemplate().update(vo.parsePo(new CornUser()));
		logger.info(this.getClass() + "用户信息更新完成");
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<UserVo> getUserBySQL(String hsql) {
		// TODO Auto-generated method stub
		logger.info(this.getClass() + "用户信息查询开始");
		List<CornUser> userpolist = this.getHibernateTemplate().find(hsql);
		List<UserVo> uservolist = new ArrayList<UserVo>();
		for (CornUser po : userpolist) {
			uservolist.add((UserVo) new UserVo().parseVo(po));
		}
		logger.info(this.getClass() + "用户信息查询结束");
		return uservolist;
	}

	@Override
	public UserVo getUserById(String id) {
		// TODO Auto-generated method stub
		CornUser po = this.getHibernateTemplate().get(CornUser.class, id);
		return (UserVo) new UserVo().parseVo(po);
	}

	@Override
	public void deleteUser(UserVo vo) {
		// TODO Auto-generated method stub
		CornUser po = this.getHibernateTemplate().get(CornUser.class, vo.getId());
		this.getHibernateTemplate().delete(po);
	}

}
